package com.cx.core.rabbitmq;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component
@Slf4j
public class MessageListener1 {

    @RabbitListener(queues = "myqueue1")
    @RabbitHandler
    public void onOrderMessage(@Payload String sellerInfo, @Headers Map<String,Object> headers, Channel channel) throws IOException {
        log.info("--------------------收到消息，开始消费-----------------------");
        log.info(sellerInfo);
        Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
        //手动确认
        //channel.basicAck(deliveryTag,false);
        //channel.basicReject(deliveryTag, true);
        throw new RuntimeException();
    }
}

